#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 1e6 + 5;
int T,n,L,m,V,ans1,ans2;

struct node{
    int d,v,a;
}x[N];

int p[N],M[N],v[N],used[N];
int cnt0 = 0;

vector <int> son[N];

bool check(int id){
    for(auto i : son[id])
        if(v[i] <= 1)
            return 0;
    return 1;
}

void init(int id){
    for(auto i : son[id])
        v[i] --;
}

bool cmp(int A,int B){
    return son[A].size() < son[B].size();
}

signed main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--){
        cin>>n>>m>>L>>V;
        //cout<<"ok"<<endl;
        ans1 = 0,cnt0 = 0,ans2 = 0;
        for(int i=1;i<=L;i++)
            son[i].clear();
        for(int i=1;i<=n;i++)
            cin>>x[i].d>>x[i].v>>x[i].a;
        for(int i=1;i<=m;i++)
            cin>>p[i];
        //sort(p + 1,p + 1 + m);
        //cout<<"ok"<<endl;
        for(int i=1;i<=n;i++){
            if(x[i].a == 0){
                if(x[i].v > V){
                    int f = 0;
                    for(int j=1;j<=m;j++)
                        if(p[j] >= x[i].d){
                            f = 1;
                            son[p[j]].push_back(i);
                        }
                    ans1 += f;
                }
                continue;
            }
            int f = 0;
            for(int j=1;j<=m;j++)
                if(p[j] >= x[i].d){
                    int dlt_x = p[j] - x[i].d;
                    int k = (x[i].v * x[i].v + 2 * x[i].a * dlt_x);
                    //if(k <= 0) continue;
                    if(k > V * V){
                        f = 1;
                        son[p[j]].push_back(i);
                    }
                }
            ans1 += f;
        }
        cout<<ans1<<" ";
        cnt0 = 0;
        for(int i=1;i<=L;i++)
            if(son[i].size())
                M[++cnt0] = i;
        sort(M + 1,M + 1 + cnt0,cmp);
        memset(v,0,sizeof(v));
        for(int i=1;i<=cnt0;i++)
            for(auto j : son[M[i]])
                v[j] ++;
        ans2 = 0;
        for(int i=1;i<=cnt0;i++){
            //if(son[M[i]].size() > son[M[i + 1]].size() && i!=cnt0)
              //  cout<<"ERR"<<endl;
            if(check(M[i]))
                init(M[i]);
            else{
                //for(auto car : son[M[i]])
                    //cout<<car<<" ";
                //cout<<endl;
                ans2 ++;
            }

        }
        cout<<m - ans2<<endl;
    }
    return 0;
}
